<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Manage extends CI_Controller {
    
    public function __construct() {
        parent::__construct();
        $this->load->helper('form');
        $this->load->model('model_gender');
        $this->load->model('model_degree');
        $this->load->model('model_job_hour');
        $this->load->model('model_job_category');
        $this->load->model('model_job_type');
        $this->load->model('model_user_type');
        $this->load->model('model_user');
        header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
	header("Cache-Control: no-store, no-cache, must-revalidate"); 
    }

        public function index()
	{
            $this->load->helper('url');
            $this->load->view('admin/manage');
            
	}
        
        //Gender 
        public function  gender()
        {
            
            $this->load->helper('url');
          
            $data['data']=$this->model_gender->genderlist();
            $this->load->view('admin/gender',$data);
        }
        
        public function  genderadd()
        {
            $this->load->helper('url');
            if(!isset($_POST['name']))
            { 
                $this->load->model('Issue');
                $issue = new Issue(); 
                if(isset($_GET['type']))
                { 
                    $issue->load($_GET['id']); 
                    $this->load->view('admin/genderadd',$issue);
                }
                else
                {
                    $issue->id=0;
                    $this->load->view('admin/genderadd',$issue);
                } 
            }
            else
            {
                $this->load->model('Issue');
                $issue = new Issue();
                if($this->input->post('id')!=0)
                {
                    $issue->id= $this->input->post('id');
                }
                $issue->name = $this->input->post('name');
                $issue->note = $this->input->post('note');
                $issue->active=TRUE;
                $issue->save();
                
                redirect('manage/gender');
            }
         
        }
        
        
        public function  genderremove()
        {
            $this->load->helper('url');
            if(isset($_GET['id']))
            {
                $id =$_GET['id'];
                $this->load->model('Issue');
                $issue = new Issue();
                $issue->load($id);
                $issue ->delete(); 
                
                echo base_url().'manage/gender';
                redirect('manage/gender');
            }
            
        }
        
        
        public function  genderseach()
        {
            $this->load->helper('url');
            $this->load->model('Issue');
            $issue = new Issue(); 
            if(isset($_GET['search'])){
                $issues['data']= $issue->genderlist($_GET['search']);
            }else
            {
                 $issues['data']= $issue->genderlist("");
            }
            $this->load->view('admin/genderseach',$issues);
            
            
            
            
        }

        
        
        // Degree
        
        
        public function  degree()
        {
            
            $this->load->helper('url');
            $degree =new Model_Degree();
            $data['data']=$degree->getlist();
            $this->load->view('admin/degree',$data);
        }
        
        public function  degreeadd()
        {
            $this->load->helper('url');
            if(!isset($_POST['name']))
            { 
                $issue = new Model_Degree(); 
                if(isset($_GET['type']))
                { 
                    $issue->load($_GET['id']); 
                    $this->load->view('admin/degreeadd',$issue);
                }
                else
                {
                    $issue->id=0;
                    $this->load->view('admin/degreeadd',$issue);
                } 
            }
            else
            { 
                $issue = new Model_Degree();
                if($this->input->post('id')!=0)
                {
                    $issue->id= $this->input->post('id');
                }
                $issue->name = $this->input->post('name');
                $issue->note = $this->input->post('note');
                $issue->active=TRUE;
                $issue->save();
                
                redirect('manage/degree');
            }
         
        }
        
        
        public function degreeremove()
        {
            $this->load->helper('url');
            if(isset($_GET['id']))
            {
                $id =$_GET['id']; 
                $issue = new Model_Degree();
                $issue->load($id);
                $issue ->delete(); 
                 
                redirect('manage/degree');
            }
            
        }
        
        
        public function degreesearch()
        {
            $this->load->helper('url'); 
            $degree = new Model_Degree(); 
            if(isset($_GET['search'])){
                $degrees['data']= $degree->getsearch(array('name','note'),$_GET['search']);
            }else
            {
                 $degrees['data']= $degree->search("");
            }
            $this->load->view('admin/degreesearch',$degrees);
            
            
        }
        
        
        // Job hours
        
        
        public function  job_hour()
        {
            
            $this->load->helper('url');
            $job =new Model_Job_Hour();
            $data['data']=$job->getlist();
            $this->load->view('admin/job_hour',$data);
        }
        
        public function  job_hour_add()
        {
            $this->load->helper('url');
            if(!isset($_POST['name']))
            { 
                $job = new Model_Job_Hour(); 
                if(isset($_GET['type']))
                { 
                    $job->load($_GET['id']); 
                    $this->load->view('admin/job_hour_add',$job);
                }
                else
                {
                    $job->id=0;
                    $this->load->view('admin/job_hour_add',$job);
                } 
            }
            else
            { 
                $job = new Model_Job_Hour();
                if($this->input->post('id')!=0)
                {
                    $job->id= $this->input->post('id');
                }
                $job->name = $this->input->post('name');
                $job->note = $this->input->post('note');
                $job->active=TRUE;
                $job->save();
                
                redirect('manage/job_hour');
            }
         
        }
        
        
        public function job_hour_remove()
        {
            $this->load->helper('url');
            if(isset($_GET['id']))
            {
                $id =$_GET['id']; 
                $issue = new Model_Job_Hour();
                $issue->load($id);
                $issue ->delete(); 
                 
                redirect('manage/job_hour');
            }
            
        }
        
        
        public function job_hour_search()
        {
            $this->load->helper('url'); 
            $job = new Model_Job_Hour(); 
            if(isset($_GET['search'])){
                $jobs['data']= $job->getsearch(array('name','note'),$_GET['search']);
            }else
            {
                 $jobs['data']= $job->search("");
            }
            $this->load->view('admin/job_hour_search',$jobs);
            
        }
        
        
        
        //Job Cateogry
        public function  job_category()
        {
            
            $this->load->helper('url');
            $job =new Model_Job_Category();
            $data['data']=$job->getlist();
            $this->load->view('admin/job_category',$data);
        }
        
        public function job_category_add()
        {
            $this->load->helper('url');
            $job = new Model_Job_Category();
            
            if(!isset($_POST['name']))
            {  
                if(isset($_GET['type']))
                { 
                    $job->load($_GET['id']); 
                }
                else
                {
                    $job->id=0;
                }  
               
                $this->load->view('admin/job_category_add',$job);
            }
            else
            { 
                
                if($this->input->post('id')!=0)
                {
                    $job->id= $this->input->post('id');
                }
                $job->name = $this->input->post('name');
                $job->note = $this->input->post('note');
                $job->active=TRUE;
                $job->save();
                
                redirect('manage/job_category');
            } 
         
        }
        
        
        public function job_category_remove()
        {
            $this->load->helper('url');
            if(isset($_GET['id']))
            {
                $id =$_GET['id']; 
                $issue = new Model_Job_Category();
                $issue->load($id);
                $issue ->delete(); 
                 
                redirect('manage/job_category');
            }
            
        }
        
        
        public function job_category_search()
        {
            $this->load->helper('url'); 
            $job = new Model_Job_Category(); 
            if(isset($_GET['search'])){
                $jobs['data']= $job->getsearch(array('name','note'),$_GET['search']);
            }else
            {
                 $jobs['data']= $job->search("");
            }
            $this->load->view('admin/job_category_search',$jobs);
            
        }
        
        
        //Job Type 
        public function  job_type()
        {
            
            $this->load->helper('url');
            $job =new Model_Job_Type();
            $data['data']=$job->getlist();
            $this->load->view('admin/job_type',$data);
        }
        
        public function job_type_add()
        {
            $this->load->helper('url');
            $job = new Model_Job_Type();
            
            if(!isset($_POST['name']))
            {  
                if(isset($_GET['type']))
                { 
                    $job->load($_GET['id']); 
                }
                else
                {
                    $job->id=0;
                }  
               
                $this->load->view('admin/job_type_add',$job);
            }
            else
            { 
                
                if($this->input->post('id')!=0)
                {
                    $job->id= $this->input->post('id');
                }
                $job->name = $this->input->post('name');
                $job->note = $this->input->post('note');
                $job->active=TRUE;
                $job->save();
                
                redirect('manage/job_type');
            } 
         
        }
        
        
        public function job_type_remove()
        {
            $this->load->helper('url');
            if(isset($_GET['id']))
            {
                $id =$_GET['id']; 
                $issue = new Model_Job_Type();
                $issue->load($id);
                $issue ->delete(); 
                 
                redirect('manage/job_type');
            }
            
        }
        
        
        public function job_type_search()
        {
            $this->load->helper('url'); 
            $job = new Model_Job_Type(); 
            if(isset($_GET['search'])){
                $jobs['data']= $job->getsearch(array('name','note'),$_GET['search']);
            }else
            {
                 $jobs['data']= $job->search("");
            }
            $this->load->view('admin/job_type_search',$jobs);
            
        }
        
        
        
        
        //User Type 
        public function  user_type()
        {
            
            $this->load->helper('url');
            $user =new Model_User_Type();
            $data['data']=$user->getlist();
            $this->load->view('admin/user_type',$data);
        }
        
        public function user_type_add()
        {
            $this->load->helper('url');
            $user = new Model_User_Type();
            
            if(!isset($_POST['name']))
            {  
                if(isset($_GET['type']))
                { 
                    $user->load($_GET['id']); 
                }
                else
                {
                    $user->id=0;
                }  
               
                $this->load->view('admin/user_type_add',$user);
            }
            else
            { 
                
                if($this->input->post('id')!=0)
                {
                    $user->id= $this->input->post('id');
                }
                $user->name = $this->input->post('name');
                $user->note = $this->input->post('note');
                $user->active=TRUE;
                $user->save();
                
                redirect('manage/user_type');
            } 
         
        }
        
        
        public function user_type_remove()
        {
            $this->load->helper('url');
            if(isset($_GET['id']))
            {
                $id =$_GET['id']; 
                $issue = new Model_User_Type();
                $issue->load($id);
                $issue ->delete(); 
                 
                redirect('manage/user_type');
            }
            
        }
        
        
        public function user_type_search()
        {
            $this->load->helper('url'); 
            $job = new Model_Job_Type(); 
            if(isset($_GET['search'])){
                $jobs['data']= $job->getsearch(array('name','note'),$_GET['search']);
            }else
            {
                 $jobs['data']= $job->search("");
            }
            $this->load->view('admin/user_type_search',$jobs);
            
        }
        
        
        
              
        //User Type 
        public function user()
        {
            
            $this->load->helper('url');
            $user =new Model_User(); 
            $user_type=new Model_User_Type();
            $data['user_type']=$user_type->get_to_combobox("Job Type");
            $data['data']=$user->getlist();
            $this->load->view('admin/user',$data);
        }
        
        public function user_add()
        {
            $this->load->helper('url');
            $user = new Model_User();
            
            $user_type =new Model_User_Type();
            
            if(!isset($_POST['id']))
            {  
                if(isset($_GET['type']))
                { 
                    $user->load($_GET['id']); 
                }
                else
                {
                    $user->id=0;
                }  
                $user->user_type_list =$user_type->get();
               
                $this->load->view('admin/user_add',$user);
            }
            else
            { 
                
                if($this->input->post('id')!=0)
                {
                    $user->id= $this->input->post('id');
                }
                $user->user_type_id=  $this->input->post('user_type_id');
                $user->first_name = $this->input->post('first_name');
                $user->last_name = $this->input->post('last_name');
                $user->business_name= $this->input->post('business_name');
                $user->user_name = $this->input->post('user_name');
                $user->password = $this->input->post('password');
                $user->email=  $this->input->post('email');
                $user->tel=  $this->input->post('tel');
                $user->active=TRUE;
                $user->save();
                
                redirect('manage/user');
            } 
         
        }
        
        
        public function user_remove()
        {
            $this->load->helper('url');
            if(isset($_GET['id']))
            {
                $id =$_GET['id']; 
                $issue = new Model_User();
                $issue->load($id);
                $issue ->delete(); 
                 
                redirect('manage/user');
            }
            
        }
        
        
        public function user_search()
        {
            $this->load->helper('url'); 
            $job = new Model_User(); 
            $user_type_id=  $this->input->post('gender_id');
            if(isset($_POST['search']))
            {
                $jobs['data']= $job->getsearch($_POST['search'],$user_type_id);
            }
            else
            {
                 $jobs['data']= $job->getsearch("",0);
            }
            $this->load->view('admin/user_search',$jobs);
            
        }
 
}
